package mensch;

import java.util.ArrayList;
import java.util.List;

public class Table {
	
	private List<Field> fields;
	private List<Player> players;
	
	public Table(List<Player> players) {
		this.players = players;
		
		// draw fields
		fields = new ArrayList<Field>();
		for (int i=0; i<40; i++) {
			fields.add(new Field(i));
		}
		for (int i=40; i<56; i++) {
			int playerID = i/4-10;
			fields.add(new HomeField(i, players.get(playerID)));
		}
		for (int i=56; i<72; i++) {
			int playerID = i/4-14;
			fields.add(new GoalField(i, players.get(playerID)));
		}
		
		// place pawns in homefields
		for (Player player : players) {
			Pawn pawn = player.getPawns().get(0);
			Field homeField = fields.get(40 + 4*player.getPlayerID());
			homeField.setPawnOnField(pawn);
			pawn.setField(homeField);
		}
		
		// Debug area
//		Pawn testPawn = players.get(1).getPawns().get(0);
//		Field testField = fields.get(5);
//		fields.get(players.get(1).getFirstHomeIndex()).setPawnOnField(null);
//		testField.setPawnOnField(testPawn);
//		testPawn.setField(fields.get(5));
	}
	
	public List<Field> getFields() {
		return fields;
	}
	
	public List<Player> getPlayers() {
		return players;
	}
}
